const MongoClient = require("mongodb").MongoClient;

const dburl = 'mongodb://localhost:27017';
const Dbs = "xuehao";
const dbname = "banji"; // 集合的名字

//然后链接数据库
MongoClient.connect(dburl, { useUnifiedTopology: true }, (err, client) => {

    if (err) return console.log("失败");
    //使用数据库进行操作

    const db = client.db(Dbs).collection(dbname);
    var result = db.find();

    var list = [];
    console.log(list);
    result.each((err, doc) => {
        if (err) return client.close();
        if (doc != null) {
            list.push(doc)
        } else {
            console.log(list);
            client.close(); 
        }
        
    });
})

